﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DXW
{
    using SKG;
    using SKG.Extend;

    using WS.Bussiness;

    public partial class FrmLogin : Form
    {
        FrmMain frmMain;
        public FrmLogin(FrmMain frmMain)
        {
            this.frmMain = frmMain;
            InitializeComponent();
        }

        WS.Catalog.CatalogSoapClient _bllCat = new WS.Catalog.CatalogSoapClient();

        public event delegate_Login Login_Thanhcong = null;

        private void FrmLogin_Load(object sender, EventArgs e)
        {
#if DEBUG
            txtTaikhoan.Text = "ldthao56";
            txtMatkhau.Text = "";
#endif
        }

        private void btnLogon_Click(object sender, EventArgs e)
        {
            int CheckLongin = _bllCat.CheckLogin(txtTaikhoan.Text, txtMatkhau.Text);
            switch (CheckLongin)
            {
                case 0:
                    XtraMessageBox.Show("Chưa nhập tên đăng nhập", STR_LOGIN_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 1:
                    XtraMessageBox.Show("Tên đăng nhập không đúng", STR_LOGIN_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 2:
                    XtraMessageBox.Show("Mật khẩu không đúng", STR_LOGIN_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 3:
                    if (Login_Thanhcong != null)
                    {
                        Login_Thanhcong(this, new Sukien { Active_TabDanhmuc = true });
                        FrmMain.Trangthai_Dangnhap = true;
                    }
                    this.Close();
                    break;
            }
        }

        private void txtMatkhau_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Return")
            {
                btnLogon_Click(null, null);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        #region Const
        private const string STR_LOGIN_ERROR = "Lổi đăng nhập";
        #endregion
    }
}
